using System.Web.Mvc;
using WroxBlog.Models;
using WroxBlog.Models.Interfaces;

namespace WroxBlog.Controllers
{
    public class PostController : Controller
    {
        private IPostRepository _postRepository;
        private ICategoryRepository _categoryRepository;
        private ICommentRepository _commentRepository;

        public PostController(IPostRepository postRepository,
            ICategoryRepository categoryRepository, ICommentRepository commentRepository)
        {
            this._postRepository = postRepository;
            this._categoryRepository = categoryRepository;
            this._commentRepository = commentRepository;
        }

        [AcceptVerbs(HttpVerbs.Get)]
        public ActionResult IndividualPost(int id)
        {
            Post post = this._postRepository.GetPost(id);

            ViewData["Title"] = post.Title;

            ViewData["Categories"] = this._categoryRepository.GetCategories();
            ViewData["Post"] = post;
            ViewData["Comments"] = this._commentRepository.GetComments(id);

            return View();
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult IndividualPost(int id, Comment comment)
        {
            comment.PostID = id;

            this._commentRepository.AddComment(comment);

            return RedirectToAction("IndividualPost");
        }
    }
}
